﻿Option Explicit On
Imports System.Drawing.Color
Imports System.Xml

Public Class Gem

    Implements ICloneable
    ' Class to hold gem information.
    Public name As String
    Public color As Integer
    Public str As Double
    Public ap As Double
    Public crit As Double
    Public haste As Double
    Public arp As Double
    Public agi As Double
    Public exp As Double
    Public hit As Double
    Public jcgem As Boolean
    Public unique As Boolean

    Enum colors
        none = 0
        red = 1
        yellow = 2
        blue = 3
        orange = 4
        green = 5
        purple = 6
        prismatic = 7
    End Enum

    Public Sub setColor(ByVal inColor As String)
        Try
            Select Case inColor
                Case "Red"
                    color = 1
                Case "Yellow"
                    color = 2
                Case "Blue"
                    color = 3
                Case "Orange"
                    color = 4
                Case "Green"
                    color = 5
                Case "Purple"
                    color = 6
                Case "Prismatic"
                    color = 7
                Case "None"
                    color = 0
            End Select
        Catch ex As Threading.ThreadAbortException
        Catch ex As Exception
            MessageBox.Show("An unexpected error has occurred. DK Optimize will exit.", "DK Optimize", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1)
            ErrLogWriter.writeLog(ex)
            End
        End Try
    End Sub

    Public Function clone() As Object Implements System.ICloneable.Clone
        Try
            Return New Gem() With {.name = name, .color = color, .jcgem = jcgem, .unique = unique, .str = str, .ap = ap, .crit = crit, .haste = haste, .agi = agi, .arp = arp, .hit = hit, .exp = exp}
        Catch ex As Threading.ThreadAbortException
            Return New Gem() With {.name = name, .color = color, .jcgem = jcgem, .unique = unique, .str = str, .ap = ap, .crit = crit, .haste = haste, .agi = agi, .arp = arp, .hit = hit, .exp = exp}
        Catch ex As Exception
            MessageBox.Show("An unexpected error has occurred. DK Optimize will exit.", "DK Optimize", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1)
            ErrLogWriter.writeLog(ex)
            End
            Return New Gem() With {.name = name, .color = color, .jcgem = jcgem, .unique = unique, .str = str, .ap = ap, .crit = crit, .haste = haste, .agi = agi, .arp = arp, .hit = hit, .exp = exp}
        End Try
    End Function

    Public Function getColor() As String
        Try
            Select Case color
                Case 0
                    getColor = "None"
                Case 1
                    getColor = "Red"
                Case 2
                    getColor = "Yellow"
                Case 3
                    getColor = "Blue"
                Case 4
                    getColor = "Orange"
                Case 5
                    getColor = "Green"
                Case 6
                    getColor = "Purple"
                Case 7
                    getColor = "Prismatic"
                Case Else
                    getColor = "None"
            End Select
        Catch ex As Threading.ThreadAbortException
            getColor = "None"
        Catch ex As Exception
            MessageBox.Show("An unexpected error has occurred. DK Optimize will exit.", "DK Optimize", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1)
            ErrLogWriter.writeLog(ex)
            End
        End Try
    End Function

    Public Function getJCGem_YN() As String
        Try
            If jcgem = True Then
                getJCGem_YN = "Yes"
            Else
                getJCGem_YN = "No"
            End If
        Catch ex As Threading.ThreadAbortException
            getJCGem_YN = "No"
        Catch ex As Exception
            MessageBox.Show("An unexpected error has occurred. DK Optimize will exit.", "DK Optimize", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1)
            ErrLogWriter.writeLog(ex)
            End
        End Try
    End Function

    Public Function getUnique_YN() As String
        Try
            If unique = True Then
                getUnique_YN = "Yes"
            Else
                getUnique_YN = "No"
            End If
        Catch ex As Threading.ThreadAbortException
            getUnique_YN = "No"
        Catch ex As Exception
            MessageBox.Show("An unexpected error has occurred. DK Optimize will exit.", "DK Optimize", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1)
            ErrLogWriter.writeLog(ex)
            End
        End Try
    End Function

    Public Function RGBColor() As Color
        Try
            Select Case color
                Case 0 ' None (Error)
                    RGBColor = FromArgb(255, 255, 255)
                Case 1 'Red
                    RGBColor = FromArgb(255, 0, 0)
                Case 2 'Yellow
                    RGBColor = FromArgb(255, 255, 0)
                Case 3 'Blue
                    RGBColor = FromArgb(0, 0, 255)
                Case 4 'Orange
                    RGBColor = FromArgb(255, 153, 0)
                Case 5 'Green
                    RGBColor = FromArgb(0, 255, 0)
                Case 6 'Purple
                    RGBColor = FromArgb(255, 0, 255)
                Case 7 'Prismatic
                    RGBColor = FromArgb(255, 255, 255)
                Case Else ' Error Case
                    RGBColor = FromArgb(255, 255, 255)
            End Select
        Catch ex As Threading.ThreadAbortException
        Catch ex As Exception
            MessageBox.Show("An unexpected error has occurred. DK Optimize will exit.", "DK Optimize", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1)
            ErrLogWriter.writeLog(ex)
            End
        End Try
    End Function

    Public Sub clear()
        ' Clears all the values of the gem.
        Try
            name = ""
            color = 0
            str = 0
            ap = 0
            crit = 0
            haste = 0
            arp = 0
            agi = 0
            exp = 0
            hit = 0
            jcgem = False
            unique = False
        Catch ex As Threading.ThreadAbortException
        Catch ex As Exception
            MessageBox.Show("An unexpected error has occurred. DK Optimize will exit.", "DK Optimize", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1)
            ErrLogWriter.writeLog(ex)
            End
        End Try
    End Sub

    Public Sub LoadFromNode(ByVal m_node As XmlNode)
        ' Takes the nodelist and sets the attributes.
        Try
            name = m_node.Attributes.GetNamedItem("name").Value
            setColor(m_node.ChildNodes.Item(0).InnerText)
            str = Double.Parse(m_node.ChildNodes.Item(1).InnerText, System.Globalization.CultureInfo.InvariantCulture)
            ap = Double.Parse(m_node.ChildNodes.Item(2).InnerText, System.Globalization.CultureInfo.InvariantCulture)
            crit = Double.Parse(m_node.ChildNodes.Item(3).InnerText, System.Globalization.CultureInfo.InvariantCulture)
            haste = Double.Parse(m_node.ChildNodes.Item(4).InnerText, System.Globalization.CultureInfo.InvariantCulture)
            arp = Double.Parse(m_node.ChildNodes.Item(5).InnerText, System.Globalization.CultureInfo.InvariantCulture)
            agi = Double.Parse(m_node.ChildNodes.Item(6).InnerText, System.Globalization.CultureInfo.InvariantCulture)
            exp = Double.Parse(m_node.ChildNodes.Item(7).InnerText, System.Globalization.CultureInfo.InvariantCulture)
            hit = Double.Parse(m_node.ChildNodes.Item(8).InnerText, System.Globalization.CultureInfo.InvariantCulture)
            jcgem = Convert.ToBoolean(m_node.ChildNodes.Item(9).InnerText)
            unique = Convert.ToBoolean(m_node.ChildNodes.Item(10).InnerText)
        Catch ex As Threading.ThreadAbortException
        Catch ex As Exception
            MessageBox.Show("An unexpected error has occurred. DK Optimize will exit.", "DK Optimize", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1)
            ErrLogWriter.writeLog(ex)
            End
        End Try
    End Sub

    Public Sub showStatic(ByVal grid As FlexCell.Grid, ByVal row As Integer, ByVal startCol As Integer)
        Try
            grid.Cell(row, startCol).Text = name
            grid.Cell(row, startCol + 1).Text = getColor()
            grid.Cell(row, startCol + 2).Text = str
            grid.Cell(row, startCol + 3).Text = ap
            grid.Cell(row, startCol + 4).Text = crit
            grid.Cell(row, startCol + 5).Text = haste
            grid.Cell(row, startCol + 6).Text = arp
            grid.Cell(row, startCol + 7).Text = agi
            grid.Cell(row, startCol + 8).Text = exp
            grid.Cell(row, startCol + 9).Text = hit
            grid.Cell(row, startCol + 10).Text = getJCGem_YN()
            grid.Cell(row, startCol + 11).Text = getUnique_YN()

            ' Color the gem cell
            grid.Cell(row, startCol + 1).BackColor = RGBColor()
            grid.Cell(row, startCol + 1).FontBold = True
        Catch ex As Threading.ThreadAbortException
        Catch ex As Exception
            MessageBox.Show("An unexpected error has occurred. DK Optimize will exit.", "DK Optimize", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1)
            ErrLogWriter.writeLog(ex)
            End
        End Try
    End Sub
End Class
